package com.language.points.javaoo;

/**
 * 类和对象 - 嵌套类 - 外部类
 * @author yll
 * @version 1.0.0
 * @date 2025/09/17 16:48
 * */
public class OuterClass {

    String outerField = "外部字段";
    static String staticOuterField = "静态外部字段";

    void outerPrint(){
        System.out.println("外部类访问:" + outerField);
        System.out.println("外部类访问:" + staticOuterField);
    }

    class InnerClass {
        void innerPrint(){
            System.out.println("内部类访问:" + outerField);
            System.out.println("内部类访问:" + staticOuterField);
        }
    }

    static class StaticInnerClass {
        void innerPrint(OuterClass outerClass){
            System.out.println("静态内部类访问:" + outerClass.outerField);
            System.out.println("静态内部类访问:" + outerClass.staticOuterField);
        }
    }

    public static void main(String[] args) {

        OuterClass outerClass = new OuterClass();
        System.out.println("**********************************");
        outerClass.outerPrint();
        System.out.println("**********************************\n\n");

        System.out.println("**********************************");
        OuterClass.InnerClass innerClass = outerClass.new InnerClass();
        innerClass.innerPrint();
        System.out.println("**********************************\n\n");

        System.out.println("**********************************");
        OuterClass.StaticInnerClass staticInnerClass = new OuterClass.StaticInnerClass();
        staticInnerClass.innerPrint(outerClass);
        System.out.println("**********************************\n\n");

    }

}
